package com.svs.framework.util;

import javax.servlet.http.HttpServletRequest;

public class UserAgentUtil {

	private final static String WINDOWS_NT = "windows nt";
	
	private final static String MACINTOSH = "macintosh" ;

	private final static String[] AGENTARRAY = { "android", "iphone", "ipod", "ipad", "windows phone", "mqqbrowser" }; // 定义移动端请求的所有可能类型

	/**
	 * 页面跳转
	 * 
	 * @param pcView
	 * @param mView
	 * @return
	 */
	public static String goPage(String pcView, String mView) {
		boolean mobileAgent = isMobileAgent();
		if (mobileAgent) {
			return mView;
		}
		return pcView;
	}



	/**
	 * 校验客户端是否是手机浏览器
	 * 
	 * @return
	 */
	public static boolean isMobileAgent() {
		HttpServletRequest request = ServletUtils.getRequest();
		String userAgent = request.getHeader("User-Agent");
		userAgent = null != userAgent ? userAgent.toLowerCase() : "";

		boolean flag = false;
		// 排除 苹果桌面系统
		if (!userAgent.contains(WINDOWS_NT) && !userAgent.contains(MACINTOSH)) {
			for (String item : AGENTARRAY) {
				if (userAgent.contains(item)) {
					flag = true;
					break;
				}
			}
		}
		return flag;
	}

}
